<template>
  <el-dialog :visible.sync="visible">
    <el-table :data="notes" border style="width: 100%">
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="备注人"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="time"
        header-align="center"
        align="center"
        label="备注时间"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form>
            <el-form-item label="NOTE：">
              <span>{{ props.row.info }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
    </el-table>
    <div class="input">
      <el-input
        type="textarea"
        placeholder="请输入内容"
        v-model="textarea"
        maxlength="200"
        show-word-limit
      >
      </el-input>
    </div>
    <div class="button">
      <el-button size="mini" type="success" @click="handleSubmit()">提交</el-button>
      <el-button size="mini" type="danger" @click="handleExit()">退出</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      textarea: "",
      notes: [],
      dataForm: {
        id: 0,
      },
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        //this.$refs["dataForm"].resetFields();
        this.$http({
          url: this.$http.adornUrl("/ord/order/getnote"),
          method: "get",
          params: this.$http.adornParams({
            id: id,
          }),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.notes = data.notes;
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    //推出
    handleExit() {
      this.visible = false;
    },
    // 提交
    handleSubmit() {
      this.$http({
        url: this.$http.adornUrl("/ord/order/setnote"),
        method: "get",
        params: this.$http.adornParams({
          id: this.dataForm.id,
          info: this.textarea,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.visible = false;
          this.textarea="";
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1000,
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
  },
};
</script>
<style>
.button {
  margin-top: 25px;
}
.input {
  margin-top: 50px;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
